package queue;

public class Worker implements Runnable {

	public Worker(SyncQueue queue) {
		_queue = queue;
	}

	public void run() {
		while (true) {
			Runnable task;
			try {
				task = (Runnable) _queue.get();
				task.run();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	protected SyncQueue _queue = null;

	public static void main(String[] args) throws Exception {
		SyncQueue queue = new SyncQueue(10);
		for (int i = 0; i < 5; i++) {
			new Thread(new Worker(queue)).start();
		}
		// 使用Thread缓冲池
		Runnable task = new MyTask();
		queue.put(task);
		//queue.get();
	}

}
